package net.da.core.bof.spi.local;

import java.util.Collection;

import net.da.core.bof.Group;
import net.da.core.bof.SysUser;
import net.da.core.entity.GroupEntity;
import net.da.core.exception.DaException;

public class GroupImpl<E extends GroupEntity> extends PersistentObjectImpl<GroupEntity> implements Group {

    public GroupImpl() {
        super();
    }

    public GroupImpl(GroupEntity entity) {
        super(entity);
    }

    public GroupEntity getEntity() {
        return (GroupEntity)super.getEntity();
    }

    public Class getEntityClass() {
        return GroupEntity.class;
    }

    public void renameGroup(String newName) {
    }

    public boolean isGroupInGroup(Group group) {
        return false;
    }

    public boolean isUserInGroup(SysUser sysUser) {
        return false;
    }

    public void setName(String name) {
        getEntity().setName(name);
    }

    public String getName() {
        return getEntity().getName();
    }

    public void setDescription(String description) {
        getEntity().setDescription(description);
    }

    public String getDescription() {
        return getEntity().getDescription();
    }

//    public void setOwner(SysUser owner) {
//        getEntity().setOwner(((SysUserImpl)owner).getEntity());
//    }
//
//    public SysUser getOwner() {
//        return businessObjectManager.getBusinessObjectByEntity(SysUser.class, getEntity().getOwner());
//    }
//
//    public void addUser(SysUser user) {
//        getEntity().getUsers().add(((SysUserImpl)user).getEntity());
//    }
//
//    public void removeUser(SysUser user) {
//        getEntity().getUsers().remove(((SysUserImpl)user).getEntity());
//    }
//
//    public void removeAllUsers() {
//        getEntity().getUsers().clear();
//    }
//
//    public Collection<SysUser> getUsers() {
//        return businessObjectManager.getBusinessObjectsByEntities(SysUser.class, getEntity().getUsers());
//    }

    public void addGroup(Group group) {
        getEntity().getGroups().add(((GroupImpl)group).getEntity());
    }

    public void removeGroup(Group group) {
        getEntity().getGroups().remove(((GroupImpl)group).getEntity());
    }

    public void removeAllGroups() {
        getEntity().getGroups().clear();
    }

    public Collection<Group> getGroups() {
        return businessObjectManager.getBusinessObjectsByEntities(Group.class, getEntity().getGroups());
    }

    public void setParentGroup(Group parentGroup) {
        getEntity().setParentGroup(((GroupImpl)parentGroup).getEntity());
    }

    public Group getParentGroup() {
        return businessObjectManager.getBusinessObjectByEntity(Group.class, getEntity().getParentGroup());
    }

    @Override
    protected void preSaveValidation() throws DaException {
    }

}
